import Vue from "vue";
import Vuex from "vuex"; // 导入vuex

import { getUsersApi } from "@/api/users.js";

Vue.use(Vuex); // 实际执行 Vuex.install(Vue)
//全局对象
const store = new Vuex.Store({
  // strict:false,
  strict: process.env.NODE_ENV === "development",
  state() {
    return {
      title: "hello vuex",
      usersList: [],
    };
  },
  mutations: {
    SET_TITLE: (state, v) => (state.title = v),
    SET_USERS_LIST: (state, v) => (state.usersList = v),
  },

  actions: {
    async getUsers(store) {
      const res = await getUsersApi();
      store.commit("SET_USERS_LIST", res);
    },
  },
});

export default store;
